from pygooglechart import Axis
from pygooglechart import SimpleLineChart
from pygooglechart import GroupedVerticalBarChart

width = 400
height = 300
def plotSolarDay(times, totals):
  maxWatts = max(totals)
  chart = SimpleLineChart(width, height,x_range=(times[0],times[-1]), y_range=(0,maxWatts))
  skip = (len(totals) + 143)/144
  chart.add_data([totals[i] for i in xrange(0, len(totals), skip)])
  chart.set_title("Watts")
  chart.set_axis_range(Axis.LEFT, 0, maxWatts)
  
  interval = (len(times) + 3)/4
  labels = [times[i].strftime("%H:%M") for i in ([0] + range(1, len(times) - 1 , interval) + [-1])] 
  chart.set_axis_labels(Axis.BOTTOM, labels)
  return chart



def barChart(labels, label, points, maxKwh):
  chart = GroupedVerticalBarChart(width, height, y_range=(0,maxKwh))
  chart.set_title(label)
  chart.add_data(points)
  chart.set_axis_labels(Axis.BOTTOM, labels)
  chart.set_axis_range(Axis.LEFT, 0, maxKwh)
  chart.set_bar_width(width/8.75)
  chart.set_bar_spacing(1)
  return chart